﻿using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform.OAuth2.Configurations;
using MiniFox.Platform.OAuth2.Events;
using MiniFox.Platform.OAuth2.Models;
using MiniFox.Platform.OAuth2.Services;

namespace MiniFox.Platform.OAuth2
{
    /// <summary>
    /// 
    /// </summary>
    [AutoRegister, SpareComponent(typeof(PassportService))]
    public interface IPassportService
    {
        /// <summary>
        /// 
        /// </summary>
        event EventHandler<RegisterEventArgs> RegisterEvent;
        /// <summary>
        /// 
        /// </summary>
        event EventHandler<SignInEventArgs> SignInEvent;
        /// <summary>
        /// 
        /// </summary>
        PassportConfiguration Configuration { get; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        bool ActivateIdentity(Ticket ticket);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <returns></returns>
        string CreateAuthUri(Ticket authTicket);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="pinCodeSignIn"></param>
        /// <returns></returns>
        bool Register(Ticket authTicket, PinCodeSignIn pinCodeSignIn);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="register"></param>
        /// <returns></returns>
        bool Register(Ticket authTicket, Register register);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="signName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        bool Register(Ticket authTicket, string signName, string password);
        /// <summary>
        /// 轮询接口，通过授权票据获得身份
        /// </summary>
        /// <param name="authTicket"></param>
        /// <returns></returns>
        AuthorizeResult SignIn(Ticket authTicket);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="passwordSignIn"></param>
        /// <returns></returns>
        bool SignIn(Ticket authTicket, PasswordSignIn passwordSignIn);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="pinCodeSignIn"></param>
        /// <returns></returns>
        bool SignIn(Ticket authTicket, PinCodeSignIn pinCodeSignIn);
        /// <summary>
        /// 凭票据重置密码(找回密码使用)
        /// </summary>
        /// <param name="ticket">票据</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        bool ResetPassword(Ticket ticket, string password);
        /// <summary>
        /// 为指定用户邮箱颁发重置密码的票据(找回密码使用)
        /// </summary>
        /// <param name="signName"></param>
        /// <param name="retakePasswordMode"></param>
        /// <returns></returns>
        bool IssueTicket(string signName, RetakePasswordMode retakePasswordMode);

        #region 移动端

        /// <summary>
        /// 在设备上使用第三方APP(如:微信、钉钉)授权登录，授权过程中将关联本系统账户，未关联成功将引发UnregisteredException异常
        /// </summary>
        /// <param name="authTicket">待授权票据</param>
        /// <param name="openAuthUser">第三方用户信息</param>
        /// <returns></returns>
        bool SignIn(Ticket authTicket, ExternalOpenAuthUser openAuthUser);
        /// <summary>
        /// 在设备上使用第三方APP(如:微信、钉钉)授权登录，授权过程中将关联本系统账户，未关联成功将引发UnregisteredException异常
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="openAuthUser"></param>
        /// <param name="scanned">是否为扫码登录</param>
        /// <returns></returns>
        bool SignIn(Ticket authTicket, ExternalOpenAuthUser openAuthUser, bool scanned);
        /// <summary>
        /// 移动终端扫码后，在移动终端对PC票据确认授权
        /// </summary>
        /// <param name="authTicket">PC端关联的登录票据</param>
        void DeviceAuthorized(Ticket authTicket);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        void BindIdentity(Ticket authTicket);
        #endregion
    }
}